﻿using System;
using System.Resources;
using Microsoft.Win32;
using System.Diagnostics;
using posmoon.Tree;

namespace posmoon.Tree
{
    class RegistrytSaver
    {
        #region

        private RegistryKey _regkey;

        #endregion

        public RegistrytSaver()
        {
            _regkey = Registry.CurrentUser;
        }

        public bool WriteValue(string ip, string user, string pass)
        {
            WriteToRegistry(ip, user, pass);
            return true;
        }

        private void WriteToRegistry(string ip, string user, string pass)
        {
            IniFile _file = new IniFile("C:\\my.ini");

            _regkey.CreateSubKey("Software\\posmoon\\"+ip);
            _regkey.Close();

            _regkey.OpenSubKey("Software\\posmoon\\" + ip, RegistryKeyPermissionCheck.ReadWriteSubTree, System.Security.AccessControl.RegistryRights.FullControl);
            _regkey.SetValue("user", user);
            _regkey.SetValue("pass", pass);
            _regkey.Flush();
            _regkey.Close();

            _file.IniWriteValue("DB", "ip", ip );
            _file.IniWriteValue("DB", "user", user);
            _file.IniWriteValue("DB", "pass", pass);
        }
    }
}
